//
//  LBMediaPresentViewController.m
//  LangBa
//
//  Created by Mac on 2017/12/21.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "LGCiTangZuPuAddPeopleViewController.h"
#import "STRadioButton.h"
@interface LGCiTangZuPuAddPeopleViewController ()
@property(nonatomic, strong) STButton                     *clearButton;
@property(nonatomic, strong) UIView                     *customView;
@property(nonatomic, strong) UIScrollView                     *scrollView;

@property(nonatomic, strong) STButton                     *addButton;
@property(nonatomic, strong) LGMenuTextFiledView                     *nameView;
@property(nonatomic, strong) LGMenuTextFiledView                     *mingView;
@property(nonatomic, strong) LGMenuTextFiledView                     *ziView;
@property(nonatomic, strong) LGMenuTextFiledView                     *shihaoView;
@property(nonatomic, strong) LGMenuTextFiledView                     *paixuView;
@property(nonatomic, strong) LGMenuTextFiledView                     *paiHangView;
@property(nonatomic, strong) LGMenuTextFiledView                     *beifenView;

@property(nonatomic, strong) STRadioButton                     *genderRadio;
@property(nonatomic, strong) STRadioButton                     *zaishiRadio;
@property(nonatomic, strong) STRadioButton                     *birstdayRadio;

@property(nonatomic, strong) STButton                     *bithDayButton;
@property(nonatomic, strong) STButton                     *qinziButton;
@property(nonatomic, strong) LGMenuTextFiledView                     *customTextView;//自定义

@property(nonatomic, strong) LGMenuTextFiledView                     *ziliaoView;
@end

@implementation LGCiTangZuPuAddPeopleViewController

- (instancetype)init
{
    if (self == [super init]) {
        self.modalPresentationStyle = UIModalPresentationOverFullScreen;
    }
    return self;
}
#pragma mark --vc 生命周期
- (void)viewDidLoad{
    [super viewDidLoad];
    [self configSubView];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self show];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
}
#pragma mark --subView
- (void)configSubView{
    __weak typeof(self) weakSelf =  self;
    self.clearButton = [[STButton alloc] initWithFrame:UIScreenFrame
                                                 title:nil
                                            titleColor:nil
                                             titleFont:0
                                          cornerRadius:0
                                       backgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.4]
                                       backgroundImage:nil
                                                 image:nil];
    [weakSelf.clearButton setClicAction:^(UIButton *sender) {
        [weakSelf dismissViewControllerAnimated:NO completion:nil];
    }];
    [self.view addSubview:_clearButton];
    
    self.customView = [[UIView alloc] initWithFrame:CGRectMake(0, UIScreenHeight, UIScreenWidth - 20, 342)];
    self.customView.centerX = UIScreenWidth / 2;
    self.customView.top = UIScreenHeight;
    self.customView.backgroundColor = [UIColor whiteColor];
    self.customView.layer.cornerRadius = 10;
    self.customView.clipsToBounds = YES;
    self.customView.top = UIScreenHeight;
    [self.view addSubview:self.customView];
    
    //sub
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(0, 0, self.customView.width, 44)
                                                     text:@"新增 "
                                                textColor:SecendTextColor
                                                     font:16
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentCenter];
    [titleLable st_showBottomLine];
    [self.customView addSubview:titleLable];
    
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, titleLable.bottom, self.customView.width, 500)];
   // [self.scrollView st_autoAdjustAllResponder];
    self.scrollView.backgroundColor = [UIColor whiteColor];
    [self.customView addSubview:self.scrollView];
    [self configScrollSubView];

    
    STButton * saveButton = [[STButton alloc] initWithFrame:CGRectMake( 30, self.scrollView.bottom  +10, 90, 30)
                                                       title:@"保存"
                                                  titleColor:[UIColor whiteColor]
                                                   titleFont:16
                                                cornerRadius:4
                                             backgroundColor:TM_redColor
                                             backgroundImage:nil
                                                       image:nil];
    saveButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [saveButton setClicAction:^(UIButton *sender) {
        [weakSelf dismiss];
    }];
    saveButton.right = self.customView.width/2 - 10;
    self.customView.height = saveButton.bottom + 30;
    [self.customView addSubview:saveButton];
    
    
    
    STButton * cacleButton = [[STButton alloc] initWithFrame:CGRectMake( 30, self.scrollView.bottom  +10, 90, 30)
                                                      title:@"取消"
                                                 titleColor:[UIColor whiteColor]
                                                  titleFont:16
                                               cornerRadius:4
                                            backgroundColor:TM_redColor
                                            backgroundImage:nil
                                                      image:nil];
    cacleButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [cacleButton setClicAction:^(UIButton *sender) {
        [weakSelf dismiss];
    }];
    cacleButton.left = self.customView.width/2 + 10;
    [self.customView addSubview:cacleButton];
}
- (void)configScrollSubView{
    __weak typeof(self) weakSelf =  self;
    self.addButton = [TMUtils deflutAddImageButtonWithActionHandle:^BOOL(UIButton *sender) {
        [weakSelf showDefultImagePicker:^(UIImage *image) {
            [sender setBackgroundImage:image forState:UIControlStateNormal];
        }];
        return NO;
    }];
    CGFloat with =self.scrollView.width - 20;
    CGFloat height = 35;
    
    self.addButton.centerX = self.scrollView.width / 2;
    self.addButton.top = 20;
    [self.scrollView addSubview:self.addButton];
    
    self.nameView = [[LGMenuTextFiledView alloc] initWithFrame:CGRectMake(10, self.addButton.bottom + 20, with, height) leftTitle:@"姓氏:"];
    [self.scrollView addSubview:self.nameView];
    
    self.mingView = [[LGMenuTextFiledView alloc] initWithFrame:CGRectMake(10, self.nameView.bottom,with , height) leftTitle:@"名:"];
    [self.scrollView addSubview:self.mingView];
    
    
    self.ziView = [[LGMenuTextFiledView alloc] initWithFrame:CGRectMake(10, self.mingView.bottom,with , height) leftTitle:@"字:"];
    [self.scrollView addSubview:self.ziView];
    
    self.shihaoView = [[LGMenuTextFiledView alloc] initWithFrame:CGRectMake(10, self.ziView.bottom,with , height) leftTitle:@"谥号:"];
    [self.scrollView addSubview:self.shihaoView];
    
    self.paixuView = [[LGMenuTextFiledView alloc] initWithFrame:CGRectMake(10, self.shihaoView.bottom,with , height) leftTitle:@"展示排序:"];
    [self.scrollView addSubview:self.paixuView];
    
    self.paiHangView = [[LGMenuTextFiledView alloc] initWithFrame:CGRectMake(10, self.paixuView.bottom,with , height) leftTitle:@"排行:"];
    [self.scrollView addSubview:self.paiHangView];
    
    
    self.beifenView = [[LGMenuTextFiledView alloc] initWithFrame:CGRectMake(10, self.paiHangView.bottom,with , height) leftTitle:@"辈分:"];
    [self.scrollView addSubview:self.beifenView];
    
    
    //性别
    UIView * genderview = [[UIView alloc] initWithFrame:CGRectMake(10,  self.beifenView.bottom + 10, self.scrollView.width - 20, 35)];
    STLabel * gendertitleLable = [[STLabel alloc] initWithFrame:CGRectMake(0, 0, 80, 35)
                                                           text:@"性别:"
                                                textColor:SecendTextColor
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentRight];
    [genderview addSubview:gendertitleLable];
    [self.scrollView addSubview:genderview];
    
    
    self.genderRadio = [[STRadioButton alloc] initWithRadio:@[@"男",@"女"] andWithFrame:CGRectMake(gendertitleLable.right + 10, 0, 200, 35)];
    [genderview addSubview:self.genderRadio];
    //zaishi
    UIView * zaishiview = [[UIView alloc] initWithFrame:CGRectMake(10,  genderview.bottom, self.scrollView.width - 20, 35)];
    [self.scrollView addSubview:zaishiview];
    STLabel * zaishititleLable = [[STLabel alloc] initWithFrame:CGRectMake(0, 0, 80, 35)
                                                           text:@"在世:"
                                                      textColor:SecendTextColor
                                                           font:14
                                                    isSizetoFit:NO
                                                  textAlignment:NSTextAlignmentRight];
    [zaishiview addSubview:zaishititleLable];
    
    self.zaishiRadio = [[STRadioButton alloc] initWithRadio:@[@"是",@"否"] andWithFrame:CGRectMake(zaishititleLable.right + 10, 0, 200, 35)];
    [zaishiview addSubview:self.zaishiRadio];
    
    //血缘关系
    UIView * xueyuanview = [[UIView alloc] initWithFrame:CGRectMake(10,  zaishiview.bottom, self.scrollView.width - 20, 35)];
    [self.scrollView addSubview:xueyuanview];
    STLabel * xueyuantitleLable = [[STLabel alloc] initWithFrame:CGRectMake(0, 0, 80, 35)
                                                           text:@"血缘关系:"
                                                      textColor:SecendTextColor
                                                           font:14
                                                    isSizetoFit:NO
                                                  textAlignment:NSTextAlignmentRight];
    [xueyuanview addSubview:xueyuantitleLable];
#define normalImage [UIImage imageNamed:@"单选未选中拷贝2"]
#define slectedImage [UIImage imageNamed:@"单选选中拷贝"]
    
    self.qinziButton = [[STButton alloc] initWithFrame:CGRectMake(xueyuantitleLable.right + 25, 0, 80, 35)
                                                     title:@"亲子"
                                                titleColor:TM_redColor
                                                 titleFont:14
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:normalImage];
    [self.qinziButton setImage:slectedImage forState:UIControlStateSelected];
    self.qinziButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    
    [self.qinziButton setClicAction:^(UIButton *sender) {
        sender.selected = !sender.selected;
    }];
    [xueyuanview addSubview:self.qinziButton];
    self.customTextView = [[LGMenuTextFiledView alloc] initWithFrame:CGRectMake(self.qinziButton.right, 0, 160, 35) leftTitle:@"自定义"];
    self.customTextView.titleLable.height = 35;
    [xueyuanview addSubview:self.customTextView];
    
    //shengri
    UIView * bithdyview = [[UIView alloc] initWithFrame:CGRectMake(10,  xueyuanview.bottom, self.scrollView.width - 20, 35)];
    [self.scrollView addSubview:bithdyview];
    STLabel * bithdyviewtitleLable = [[STLabel alloc] initWithFrame:CGRectMake(0, 0, 80, 35)
                                                           text:@"生日:"
                                                      textColor:SecendTextColor
                                                           font:14
                                                    isSizetoFit:NO
                                                  textAlignment:NSTextAlignmentRight];
    [bithdyview addSubview:bithdyviewtitleLable];
    
    self.birstdayRadio = [[STRadioButton alloc] initWithRadio:@[@"阳历",@"阴历"] andWithFrame:CGRectMake(zaishititleLable.right + 10, 0, 200, 35)];
    [bithdyview addSubview:self.birstdayRadio];

    
   self.bithDayButton= [[STButton alloc] initWithFrame:CGRectMake(self.paixuView.titleLable.right + 25, bithdyview.bottom + 10, self.paixuView.textFiled.width, 35)
                                                     title:nil
                                                titleColor:SecendTextColor
                                                 titleFont:13
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:nil];
    [self.bithDayButton st_setBorderWith:1 borderColor:TM_lineColor cornerRadius:0];
    [self.scrollView addSubview:self.bithDayButton];
    [self.bithDayButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedTimeButton];
    }];
    
    self.ziliaoView = [[LGMenuTextFiledView alloc] initWithFrame:CGRectMake(10, self.bithDayButton.bottom + 10, self.scrollView.width - 20, 60) leftTitle:@"个人资料:"];
    [self.scrollView addSubview:self.ziliaoView] ;
    self.scrollView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
    self.scrollView.contentSize = CGSizeMake(0,_ziliaoView.bottom );
}

#pragma mark --Private Method
- (void)show{
    [UIView animateWithDuration:0.6
                          delay:0
         usingSpringWithDamping:0.6
          initialSpringVelocity:0.7
                        options:UIViewAnimationOptionLayoutSubviews
                     animations:^{
                          self.customView.centerY = UIScreenHeight / 2;
                     } completion:^(BOOL finished) {
                         
                     }];
}
- (void)dismiss{
    [self.view endEditing:YES];
    [UIView animateWithDuration:0.25 animations:^{
        self.customView.top = UIScreenHeight;
        self.clearButton.alpha = 0;
    } completion:^(BOOL finished) {
        [self dismissViewControllerAnimated:NO completion:nil];
    }];
}
- (void)dismissWithHandle:(void(^)())handle{
    [self.view endEditing:YES];
    [UIView animateWithDuration:0.25 animations:^{
        self.customView.top = UIScreenHeight;
        self.clearButton.alpha = 0;
    } completion:^(BOOL finished) {
        [self dismissViewControllerAnimated:NO completion:^{
            if (handle) {
                handle();
            }
        }];
    }];
}
#pragma mark --Action Method

- (void)onSelectedCancleButton{
    
    [self dismiss];
    
}
- (void)onSelectedWhiteView{
    [self.view endEditing:YES];
}

- (void)onSelctedTimeButton{
    STPickerViewController * picker = [[STPickerViewController alloc] initWithDefualtDatePickerWithHandle:^(NSDate *date) {
        [self.bithDayButton setTitle:date.st_yyyyMMddByLineWithDate forState:UIControlStateNormal];
    }];
    [self presentViewController:picker animated:NO completion:nil];
}
@end




